package com.tianhui.consignortwofei.mvp.ui.activity;

import android.os.Bundle;

import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonResponse;
import com.fgs.common.CommonView;
import com.fgs.common.progress.ExceptionHandle;
import com.fgs.common.progress.ObserverResponseListener;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseDataListActivity;
import com.tianhui.consignortwofei.base.BaseFragment;
import com.tianhui.consignortwofei.mvp.model.UserInfoModel;
import com.tianhui.consignortwofei.mvp.model.enty.TongHuaLogBean;
import com.tianhui.consignortwofei.mvp.ui.adapter.LiuLanListAdapter;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.view.YCRefreshView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * @author fgs
 * @date 2020/4/28
 * @description
 **/
public class LiuLanLogActivity extends BaseDataListActivity {

    @BindView(R.id.layout_data_list_recyclerView)
    YCRefreshView layout_data_list_recyclerView;
//    @BindView(R.id.inpiv_zhuanghuo)
//    InputItemView inpiv_zhuanghuo;


    private UserInfoModel mModel;
    private String sourcenum;
    private LiuLanListAdapter mMessageListAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_tonghua_log;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }



    @Override
    public RecyclerArrayAdapter createAdapter() {
        mMessageListAdapter = new LiuLanListAdapter(this);
        return mMessageListAdapter;
    }

    @Override
    protected void initListener() {
//        mAdapter.setOnItemClickListener(new OnItemClickListener() {
//            @Override
//            public void onItemClick(int position) {
//                DriverInfo driverInfo = (DriverInfo) mAdapter.getAllData().get(position);
//                if (driverInfo != null && !TextUtils.isEmpty(driverInfo.drivertel)) {
//                    setResult(driverInfo);
//                }
//            }
//        });
    }

    @Override
    public void requestDataList(int page, boolean isDialog) {
//        mSearchKey = searchEditText.getText().toString();
//        if (checkSearchKey(mSearchKey)) {
            requestDriverList(page, isDialog);
//        } else {
//            stopRefresh();
//        }
    }

    @Override
    public void initData() {
        setTitle("浏览记录");

        Bundle bundle = getIntent().getExtras();
        sourcenum = bundle.getString("sourcenum");
    }

    @Override
    public BaseFragment createFragment() {
        return null;
    }



//    @OnClick(R.id.tv_false)
//    public void selectFalse() {
////        csv_zhuanghuo.setContent("");
//        inpiv_zhuanghuo.setContent("");
//        dressListAdapter.removeAll();
//    }

    public void requestDriverList(int page,boolean isDialog) {
        Map<String, String> map = new HashMap<>();
        map.put("billno", sourcenum);
        map.put("order", "desc");
        map.put("page", page+"");
        map.put("limit", "20");
        map.put("sort", "a.create_time");
        if (mModel == null) {
            mModel = new UserInfoModel();
        }
        mModel.getLiuLan(this, map, isDialog, bindLifecycle(), new ObserverResponseListener<CommonResponse<TongHuaLogBean>>() {
            @Override
            public void onNext(CommonResponse<TongHuaLogBean> commonResponse) {
                if (!isFinishing() && !isDestroyed()) {
                    if (commonResponse.getCode() == 20000) {
                        List<TongHuaLogBean.RecordsDTO> list = commonResponse.getData().getRecords();
//                        List<TongHuaLogBean> list = commonResponse.getData();
//                        List<TongHuaLogBean> resultList = new ArrayList<>();

                        if (list != null && list.size() > 0) {
                            setPageInfo(1, 1);
//                            for (TongHuaLogBean.RecordsDTO info : list) {
//                                if (info.drivertel.equals(phone)) {
//                                    resultList.add(info);
//                                }
//                            }
                            if (list.size() > 0) {
                                showDataList(list);
                            } else {
                                showEmptyView();
                            }

                        } else {
                            showEmptyView();
                        }

                    } else {
                        showToast(commonResponse.getMsg());
                    }
                }
            }


            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {
                showToast(e.message);
            }
        });
    }




}
